package com.thingple.usb.stream;

import android.util.Log;

import com.thingple.util.Strings;

public abstract class EventAware extends AbstractProcessor {

    private static final String TAG = EventAware.class.getName();

    @Override
    protected void onTx(byte[] bytes, int n, boolean async) {
        onTrace("tx:[" + n + "]" + Strings.hex(bytes));
        Log.d(TAG, "tx:" + Strings.hex(bytes));
        if (streamDownListener != null) {
            streamDownListener.onWrite(bytes, n, async);
        }
    }
    @Override
    protected void onRx(byte[] bytes, int n) {

        onTrace("rx:[" + n + "]" + Strings.hex(bytes));
        if (streamUpListener != null) {
            streamUpListener.onData(bytes, n);
        }
    }
    @Override
    protected void onTrace(String content) {
        if (traceListener != null) {
            traceListener.onTrace(content);
        }
    }
    @Override
    protected void onErr(Exception e) {
        Log.d(TAG, e.toString());
        e.printStackTrace();

        if (errorListener != null) {
            errorListener.onErr(e);
        }
    }
}
